home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3 / CHAPTE15 / DEVCAPS.C next >
C/C++ Source or Header  |  1996-04-28  |  6KB  |  199 lines

  1. #include <windows.h>  
  2. #include "DevCaps.h"
  3.  
  4. #if defined (WIN32)
  5.     #define IS_WIN32 TRUE
  6. #else
  7.     #define IS_WIN32 FALSE
  8. #endif
  9.  
  10. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  11. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  12. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  13.  
  14. HINSTANCE hInst;   // current instance
  15.  
  16. LPCTSTR lpszAppName = "MyApp";
  17. LPCTSTR lpszTitle   = "auxGetDevCaps"; 
  18.  
  19. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  20.  
  21.  
  22. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  23.                       LPTSTR lpCmdLine, int nCmdShow)
  24. {
  25.    MSG      msg;
  26.    HWND     hWnd; 
  27.    WNDCLASS wc;
  28.  
  29.    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  30.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  31.    wc.cbClsExtra    = 0;                      
  32.    wc.cbWndExtra    = 0;                      
  33.    wc.hInstance     = hInstance;              
  34.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  35.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  36.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  37.    wc.lpszMenuName  = lpszAppName;              
  38.    wc.lpszClassName = lpszAppName;              
  39.  
  40.    if ( IS_WIN95 )
  41.    {
  42.       if ( !RegisterWin95( &wc ) )
  43.          return( FALSE );
  44.    }
  45.    else if ( !RegisterClass( &wc ) )
  46.       return( FALSE );
  47.  
  48.    hInst = hInstance; 
  49.  
  50.    hWnd = CreateWindow( lpszAppName, 
  51.                         lpszTitle,    
  52.                         WS_OVERLAPPEDWINDOW | WS_VSCROLL, 
  53.                         CW_USEDEFAULT, 0, 
  54.                         CW_USEDEFAULT, 0,  
  55.                         NULL,              
  56.                         NULL,              
  57.                         hInstance,         
  58.                         NULL               
  59.                       );
  60.  
  61.    if ( !hWnd ) 
  62.       return( FALSE );
  63.  
  64.    ShowWindow( hWnd, nCmdShow ); 
  65.    UpdateWindow( hWnd );         
  66.  
  67.    while( GetMessage( &msg, NULL, 0, 0) )   
  68.    {
  69.       TranslateMessage( &msg ); 
  70.       DispatchMessage( &msg );  
  71.    }
  72.  
  73.    return( msg.wParam ); 
  74. }
  75.  
  76.  
  77. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  78. {
  79.     WNDCLASSEX wcex;
  80.  
  81.    wcex.style         = lpwc->style;
  82.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  83.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  84.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  85.    wcex.hInstance     = lpwc->hInstance;
  86.    wcex.hIcon         = lpwc->hIcon;
  87.    wcex.hCursor       = lpwc->hCursor;
  88.    wcex.hbrBackground = lpwc->hbrBackground;
  89.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  90.    wcex.lpszClassName = lpwc->lpszClassName;
  91.  
  92.    // Added elements for Windows 95.
  93.    //...............................
  94.    wcex.cbSize = sizeof(WNDCLASSEX);
  95.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  96.                             IMAGE_ICON, 16, 16,
  97.                             LR_DEFAULTCOLOR );
  98.             
  99.    return RegisterClassEx( &wcex );
  100. }
  101.  
  102.  
  103.  
  104. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  105. {
  106.    switch( uMsg )
  107.    {
  108.       case WM_COMMAND :
  109.               switch( LOWORD( wParam ) )
  110.               {
  111.                  case IDM_TEST :
  112.                         {
  113.                            AUXCAPS  auxcaps;
  114.                            UINT     nDevId;
  115.                            UINT     nNbrAuxDevices = auxGetNumDevs();
  116.                            MMRESULT rc;
  117.  
  118.                            for (nDevId = 0; nDevId < nNbrAuxDevices; nDevId++)
  119.                            {
  120.                               rc = auxGetDevCaps( nDevId, &auxcaps, 
  121.                                                   sizeof(auxcaps) );
  122.  
  123.                               if ( rc == MMSYSERR_NOERROR && 
  124.                                  (auxcaps.wTechnology & AUXCAPS_CDAUDIO) &&
  125.                                  (auxcaps.dwSupport & AUXCAPS_VOLUME) )
  126.                               {
  127.                                   DWORD dwVol;
  128.                                   WORD wLeft, wRight;
  129.  
  130.                                   if ( auxGetVolume( nDevId, &dwVol ) != 
  131.                                        MMSYSERR_NOERROR )
  132.                                       break;
  133.                                   
  134.                                   wLeft  = LOWORD( dwVol );
  135.                                   wRight = HIWORD( dwVol );
  136.  
  137.                                   // check left/(mono?) volume 
  138.  
  139.                                   if ( wLeft > 0x7777 )  
  140.                                       wLeft = 0x7777;
  141.                                   
  142.                                   if ( wRight > 0x7777 && 
  143.                                      (auxcaps.dwSupport & AUXCAPS_LRVOLUME) )
  144.                                       wRight = 0x7777;
  145.                                   
  146.                                   rc = auxSetVolume( nDevId, 
  147.                                                      MAKELONG( wLeft, wRight ) );
  148.                               }
  149.                            }
  150.                         }
  151.                         break;
  152.                  
  153.                  case IDM_ABOUT :
  154.                         DialogBox( hInst, "AboutBox", hWnd, About );
  155.                         break;
  156.  
  157.                  case IDM_EXIT :
  158.                         DestroyWindow( hWnd );
  159.                         break;
  160.               }
  161.               break;
  162.       
  163.       case WM_DESTROY :
  164.               PostQuitMessage(0);
  165.               break;
  166.  
  167.       default :
  168.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  169.    }
  170.  
  171.    return( 0L );               
  172. }
  173.  
  174.  
  175. LRESULT CALLBACK About( HWND hDlg,           
  176.                         UINT message,        
  177.                         WPARAM wParam,       
  178.                         LPARAM lParam)
  179. {
  180.    switch (message) 
  181.    {
  182.        case WM_INITDIALOG: 
  183.                return (TRUE);
  184.  
  185.        case WM_COMMAND:                              
  186.                if (   LOWORD(wParam) == IDOK         
  187.                    || LOWORD(wParam) == IDCANCEL)    
  188.                {
  189.                        EndDialog(hDlg, TRUE);        
  190.                        return (TRUE);
  191.                }
  192.                break;
  193.    }
  194.  
  195.    return (FALSE); 
  196. }
  197.  
  198.  
  199.